﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BeniBastanYaratProject.Uye
{
    public partial class AdresDetay : System.Web.UI.Page
    {
        DBBaglantiDataContext db = new DBBaglantiDataContext();

        
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Page.IsPostBack)
                return;
            if (Request.QueryString["uid"] != null)
            {
              ViewState["adresid"]= int.Parse(Request.QueryString["uid"]);

              var sorgu = (from x in db.UyeAdreslers where x.AdresID == Convert.ToInt32(ViewState["adresid"]) select x).SingleOrDefault();

                if (sorgu!=null )
                {

                    txtbilgi.Text = sorgu.AdresBilgisi;
                    txttarif.Text = sorgu.AdresTarif;
                    txtnot.Text = sorgu.AdresNot;
                    txtadi.Text = sorgu.AdresAdi;

                    
                }

            }

        }

        protected void guncelle_Click(object sender, EventArgs e)
        {
            var sorgu = (from x in db.UyeAdreslers where x.AdresID == Convert.ToInt32(ViewState["adresid"]) select x).SingleOrDefault();

            if (sorgu != null)
            {
                sorgu.AdresBilgisi = txtbilgi.Text;
                sorgu.AdresTarif = txttarif.Text;
                sorgu.AdresNot = txtnot.Text;
                db.SubmitChanges();

                txtbilgi.Text = "";
                txtnot.Text = "";
                txttarif.Text = "";
                txtadi.Text = "";
                Response.Redirect("AdresBilgiIslem.aspx");


            }
        }

        protected void btnsil_Click(object sender, EventArgs e)
        {
            //var sil = (from x in db.UyeAdreslers where x.AdresID == Convert.ToInt32(ViewState["adresid"]) select x).SingleOrDefault();

            //if (sil != null)
            //{

            //    db.UyeAdreslers.DeleteOnSubmit(sil);
            //    db.SubmitChanges();
            //    Response.Redirect("~/AdresBilgiIslem.aspx");
            //}

        }
    }
}